/*
 This file is part of Musimage, a project which makes possible listen to music
 and, at the same time, watch pictures related with that music.
 Copyright (C) 2006  David Garcia Narbona 

 Musimage is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 Musimage is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with Musimage; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
package brokerExt;

import jade.core.Agent;

import jade.lang.acl.ACLMessage;
import jade.core.behaviours.OneShotBehaviour;

// Clase que modela la conversacion del broker externo
public class ConversationThread extends OneShotBehaviour {

	// ** Atributos **////////////////////////////////////
	private ACLMessage brokerRequest;

	private DataBaseManager databaseManager;

	// ////////////////////////////////////////////////////

	// ** Metodos **//////////////////////////////////////

	// Constructor
	public ConversationThread(Agent _agent, ACLMessage _requestMessage) {

		databaseManager = DataBaseManager.getInstance();

		brokerRequest = _requestMessage;
	}

	// Metodo a implementar en el que se encuentran todas las operacions
	// que debe realizar el comportamiento
	public void action() {

		reply(brokerRequest);
	}

	// Metodo que responde al cliente conforme ha recibido la peticion
	private void reply(ACLMessage request) {

		ACLMessage reply = request.createReply();

		if (isSong((String) request.getContent())) {

			reply.setPerformative(ACLMessage.INFORM);
		} else {

			reply.setPerformative(ACLMessage.FAILURE);
		}

		myAgent.send(reply);
	}

	// Metodo que verifica si el archivo RDF para la cancion existe en la BD
	private boolean isSong(String RDFFileName) {

		return true;
	}

	// ///////////////////////////////////////////////////////////
}
